package GUILayer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;


@SuppressWarnings("serial")
public class PopupBestilVare extends PopupWindow {
	private JTextField textFirmanavn;
	private JTextField textField;
	private JTextField textField_1;

	public PopupBestilVare(Updateable mother) //throws HeadlessException - why?
	{
		super(mother);
		setTitle("Bestil vare");

		JLabel lblFirmaNavn = new JLabel("Firmanavn");

		JButton btnAnnuller = new JButton("Annuller");
		btnAnnuller.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				quit();
			}
		});
		JButton btnOpret = new JButton("Bestil");
		btnOpret.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent arg0)
			{
				getMother().update();
				quit();
			}
		});
		
		JButton btnRydFelter = new JButton("Ryd Felter");
		btnRydFelter.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent arg0)
			{
				clearFields();
			}
		});

		textFirmanavn = new JTextField();
		textFirmanavn.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Vare");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JLabel lblAntal = new JLabel("Antal");
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);

		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblFirmaNavn)
								.addComponent(lblNewLabel)
								.addComponent(lblAntal))
							.addGap(24)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 264, GroupLayout.PREFERRED_SIZE)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, 264, GroupLayout.PREFERRED_SIZE)
								.addComponent(textFirmanavn, 264, 264, 264)))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnRydFelter)
							.addGap(18)
							.addComponent(btnAnnuller)
							.addGap(18)
							.addComponent(btnOpret)))
					.addContainerGap(79, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblFirmaNavn)
						.addComponent(textFirmanavn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblAntal)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(34)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnRydFelter)
						.addComponent(btnAnnuller)
						.addComponent(btnOpret))
					.addGap(210))
		);

		getContentPane().setLayout(groupLayout);
		pack();
	}

	
	public void clearFields()
	{
		textFirmanavn.setText(null);
		textField.setText(null);
		textField_1.setText(null);
		
	}
}
